let cur = 0;
// urls 链接数组
const downfile = (urls,type="image")=>{
	uni.showLoading({
		title: '下载中...',
		mask:true
	})
	for (let i = 0; i < urls.length; i++) {
		uni.downloadFile({
			url: urls[i], //url为图片地址
			success: res => {
				if (res.statusCode === 200) {
					if(type=='image'){
						uni.saveImageToPhotosAlbum({
							filePath: res.tempFilePath,
							success:res=>{
								cur++;
								if(cur==urls.length){
									uni.showToast({
										title: '下载完成'
									})
								}
							},
							fail: function(e) {
								uni.showToast({
									title: '保存失败，请稍后重试',
									icon:'none'
								})
								console.log(e,'保存失败')
							}
						});
					}else{
						uni.saveVideoToPhotosAlbum({
							filePath: res.tempFilePath,
							success:res=>{
								cur++;
								if(cur==urls.length){
									uni.showToast({
										title: '下载完成'
									})
								}
							},
							fail: function(e) {
								uni.showToast({
									title: '保存失败，请稍后重试',
									icon:'none'
								})
								console.log(e,'保存失败')
							}
						});
					}
					
				} else {
					uni.showToast({
						title: '保存失败，请稍后重试',
						icon:'none'
					})
					console.log(res,'下载失败')
				}
			}
		});
	}
}

export {
	downfile
}